# -*- coding: utf-8 -*-
# @Time : 2021/9/17 16:02
# @Author : hello
# @Email : xxx@gmail.com
# @File : MRSX_ST_FL_003.py
# @Project : mryx_test

"""验证每日优鲜-验证搜索商品添加进购物车后删除功能"""

from appium import webdriver
from selenium.webdriver.common import desired_capabilities
from appium.webdriver.common.mobileby import MobileBy as By
from selenium.webdriver.support.wait import WebDriverWait
from time import sleep

desired_capabilities={
    "platformName":"Android",
    "deviceName":"127.0.0.1:62025",
    "platformVersion":"5.1.1",
    "appPackage":"cn.missfresh.application",
    "appActivity":"cn.missfresh.module.base.main.view.MainActivity",
    "noReset":"True"
}
driver=webdriver.Remote("http://localhost:4723/wd/hub",desired_capabilities)
try:
    # 点击分类-进入分类页
    driver.implicitly_wait(30)
    fl = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("分类")')
    driver.find_element(*fl).click()
    sleep(3)
    # 点击搜索
    ss = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("搜索")')
    driver.find_element(*ss).click()
    sleep(3)
    # 搜索框输入内容
    nr = (By.XPATH, '//android.widget.EditText[@resource-id=\"cn.missfresh.application:id/search_view\"]')
    driver.find_element(*nr).send_keys("肉蛋")
    sleep(3)
    # 点击搜索
    ssnr = (By.XPATH, '//android.widget.TextView[@resource-id=\"cn.missfresh.application:id/tv_search\"]')
    driver.find_element(*ssnr).click()
    sleep(7)
    #点击添加商品数量2次
    for i in range(2):
        driver.tap([(301,574),(340,613)])
        sleep(5)
    #点击购物车
    driver.tap([(638,38),(720,120)])
    sleep(3)
    #点击删除
    sc=(By.ID,'cn.missfresh.application:id/tv_delete')
    driver.find_element(*sc).click()
    sleep(3)
    #确认删除
    ss = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("确定")')
    driver.find_element(*ss).click()
    sleep(4)
    # 断言
    # qd = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("购物车里空空如也")')

except Exception as e:
    raise e
finally:
    sleep(3)
    # driver.quit()